var timer=null
var index = 0
var close = false

// 数字跳动
function jumpnumber( startnumb, targetnumb, selecter,step, speed) {
    var stepnum = 0
    var numbjump = setInterval(function(){
        let strstartnumber = startnumb
        stepnum +=step
        strstartnumber += stepnum
        $(selecter).text(strstartnumber)
        if(strstartnumber >= targetnumb){
            clearInterval(numbjump)
        }
    },speed)
}
// 银行轮播
function play(){
    timer = setInterval(function () {
        if (index < 2){
            index++
            var leftoffset = 0-index * 268
            $('.company-list').css({'left':leftoffset+ 'px'})
        }
        else {
            index = 0
            $('.company-list').css({'left':0})
        }
    },3000)
}
// 公告轮播
function autoply() {
    var wrap = $('.wrap-annouce')
    var text2 = $('.annouce-text2')
    setInterval(function () {
        if (wrap.scrollLeft() >= text2.width())
        {
            wrap.scrollLeft(wrap.scrollLeft()-text2.width())
        }
        else {
            wrap.scrollLeft(wrap.scrollLeft()+1)
        }
    },50)
}





$(function () {
    const sider = $('.fixed-sider')
    const backicon = $('.sidericon-4')
    const prd = $('.product')
    const product1 = $('.product1')

    prd.hover(function (event) {
            $('.wrap').stop().animate({'height':'840px'},280)},
        function (event) {
            $('.wrap').stop().animate({'height':'627px'},280)}
    )

    product1.hover(function (event) {
            $(this).find('.wrap-detail').stop().animate({'height':'213px'},150)},
        function (event) {
            $(this).find('.wrap-detail').stop().animate({'height':'0'},200)}
    )

    backicon.on('click', function () {
        window.scrollTo(0,0)
    })


    const toplogo = $('.top-logo img')
    const top1= $('.top')
    const navitemlist = $('.item-list li a')
    const toplocation = $('.top-location')
    const locationtext = $('.top-location span:nth-of-type(2)')
    const leftul = $('.daikuan-bt')
    const daikuan = $('.daikuan')
    const foot = $('.fix-bottom')
    const cate = $('.category li')
    const line = $('.line')
    const button = $('.button button')

    window.onscroll = function () {
        if (top1.offset().top >0 ){
            top1.addClass('active')
            toplogo.attr('src','static/img/index/flogo.png')
            navitemlist.addClass('active')
            locationtext.addClass('active')
            cate.addClass('active')
            line.addClass('active')
            toplocation.addClass('active')
            if (!close){
                foot.slideDown()
            }
        }

        if(window.scrollY > 1500){
            sider.show('slow')
        }
        else {
            sider.hide('slow')
        }

        if (top1.offset().top === 0 ){
            top1.removeClass('active')
            toplogo.attr('src','static/img/index/toplogo.png')
            navitemlist.removeClass('active')
            locationtext.removeClass('active')
            cate.removeClass('active')
            line.removeClass('active')
            toplocation.removeClass('active')
            foot.slideUp()
        }
    }

    leftul.on('click','li',function (event) {

        var target = $(event.target);
        var targetlist = target.parent().find('li')

        $.each(targetlist,function (i,n) {
            $(n).removeClass('active')
        })
        target.addClass("active");
    })

    daikuan.on('click', function (event) {
        const name = event.target.innerText
        const changelist = $(event.target).parents('.daikuan').find('.list-1')
        $.ajax({
            url:'http://123.56.251.69:1006/index.php/api/auth/raiders',
            success:function (ret) {
                const res = ret.data[name]
                for (let i = 0;i< res.length;i++){
                    const spanlist = changelist[i].getElementsByTagName('span')
                    spanlist[0].innerText = res[i]['problem']
                    spanlist[1].innerText = res[i]['details']
                }
            }
        })
    })

    button.on('click', function () {
        let name = $('.input-form input[name="name"]').val()
        let phone = $('.input-form input[name="phone"]').val()
        let money = $('.input-form input[name="money"]').val()
        let test = $('.input-form input[name="test"]').val()
        let sex = $('.input-form input[name="sex"]:checked').val()
        const data = {
           'name':name,
           'call':phone,
            'amount':money,
            'sex':sex,
           'number':test
        }
        $.post('http://123.56.251.69:1006/index.php/api/auth/application/',data).then(
            function (data) {
                console.log(data)
            }
        )
    })



    jumpnumber(32000,83828272, '.mtext-moneynumb',300000,1)
    jumpnumber(100,8965, '.mtext-businessnumb',300,50)

    play()
    autoply()

    $('.fix-bottom_close').on('click', function () {
        close = true
        $('.fix-space').hide()
        foot.hide()
    })
})



